<?php

require_once( "../application.php" );
require_once( "Chart.class.php" );

$app	=	new Application();

$app->IsAuthenticationRequired(TRUE);



$chart	=	new	Chart();


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb" dir="ltr">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta name="robots" content="index, follow" />
	<meta name="keywords" content="brunom4ciel" />
	<meta name="description" content="Semantic web" />
	<meta name="generator" content="brunom4ciel" />
	<title>Bruno Maciel</title>
  
  	<link rel="stylesheet" href="css/generic.css" type="text/css" />

<style>

body {
  font: 10px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.bar {
  fill: steelblue;
}

.x.axis path {
  display: none;
}

</style>

</head>
<body class="contentpane">
	
	<script src="http://d3js.org/d3.v3.min.js"></script>


<a href="../index.php">Home</a>	
<a href="<?php echo $_SERVER['PHP_SELF'] ;?>"><h1>linguagens de Programação</h1> </a>
	<h1>Bar Chart</h1>
	
	
<script>

var margin = {top: 20, right: 20, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var formatPercent = d3.format("d");

var x = d3.scale.ordinal()
    .rangeRoundBands([0, width], .1);

var y = d3.scale.linear()
    .range([height, 0]);

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom");

var yAxis = d3.svg.axis()
    .scale(y)
    .orient("left")
    .tickFormat(formatPercent);

var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

d3.tsv("http://cin.ufpe.br/~bifm/projeto/survey/chart/chart.php?action=ajax&chart=linguagensquantidade", function(error, data) {

  data.forEach(function(d) {
    d.quantidade = +d.quantidade;
  });

  x.domain(data.map(function(d) { return d.linguagem; }));
  y.domain([0, d3.max(data, function(d) { return d.quantidade; })]);
  
  
//alert( d3.max(data, function(d) { return d.quantidade; }) );


  svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(xAxis);

  svg.append("g")
      .attr("class", "y axis")
      .call(yAxis)
    .append("text")
      .attr("transform", "rotate(-90)")
      .attr("y", 6)
      .attr("dy", ".71em")
      .style("text-anchor", "end")
      .text("quantidade");

  svg.selectAll(".bar")
      .data(data)
    .enter().append("rect")
      .attr("class", "bar")
      .attr("x", function(d) { return x(d.linguagem); })
      .attr("width", x.rangeBand())
      .attr("y", function(d) { return y(d.quantidade); })
      .attr("height", function(d) { return height - y(d.quantidade); });

});

</script>	


</body>
</html>